package com.example.mynews;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

import static java.security.AccessController.getContext;

/**
 * Created by 王聪 on 2018/5/28.
 */

public class ComAdapter extends BaseAdapter {
    private Context context;
    private List<Comm> comms=new ArrayList<>();

    public ComAdapter(Context context, List<Comm> comms){
        this.context=context;
        this.comms=comms;
    }
    @Override
    public int getCount() {
        return comms.size();
    }

    @Override
    public Object getItem(int i) {
        return comms.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view==null){
            view = LayoutInflater.from(context).inflate(R.layout.comment_list_item,viewGroup,false);
            ViewHolder viewHolder=new ViewHolder();
            viewHolder.username=view.findViewById(R.id.com_username);
            viewHolder.date=view.findViewById(R.id.com_date);
            viewHolder.content=view.findViewById(R.id.com_content);
            view.setTag(viewHolder);
        }

        final Comm comm=comms.get(i);
        ViewHolder viewHolder= (ViewHolder) view.getTag();
        viewHolder.username.setText(comm.getUsername());
        Log.e("username",comm.getUsername());
        viewHolder.date.setText(comm.getDate());
        viewHolder.content.setText(comm.getContent());

        return view;
    }

    class ViewHolder{
        TextView username;
        TextView date;
        TextView content;
    }
}
